<?php
require_once("../../../config.inc.php");
require_once("../../../app/_inc/include.php");

$objUser = $_SESSION[USEROBJ];
$aDataArea = $objUser->getDataArea();
$sep = "";
$sCondDataArea = "";
if(count($aDataArea) > 0){
	$sCondDataArea = "WHERE data_area IN (";
	foreach($aDataArea as $dataArea=>$perm){
		if($perm != "N"){
			$sCondDataArea .= $sep."'".$dataArea."'";
			$sep = ", ";
		}
	}
	$sCondDataArea .= ")";
}

$sSQL = "SELECT * FROM data_area $sCondDataArea ORDER BY data_area";
$errMsg = "";
if(!$query = $objSDAO->query($sSQL)){
	$errMsg = $objSDAO->error;
	$errCode = $objSDAO->errno;
}
$aOpz = array("kMenu"=>'dam');
echo(headerHTML($aOpz));
echo(bodyHTML($aOpz));
$aCmd = array(
					"ins"=>array("pag"=>"dataAreaIns.php?",
										"title"=>_t("new Data-Area"),
										"text"=>_t("new Data-Area"),
										"perm"=>"newda"),
					"back"=>array("pag"=>$objUser->getHistory(-1,false),
										"title"=>$objUser->getHistoryText(-1),
										"text"=>$objUser->getHistoryText(-1),
										"perm"=>"")
					);
echo(commandsHTML($aCmd));	
if($errMsg == ""){
	$numElem = 0;
	echo("<table class='tabl01' width=\"100%\" cellpadding=\"3\" cellspacing=\"2\">\n");
	echo("<tr>" .
			"<td class=\"titl01\" colspan=\"4\">"._t("List of Data-Areas")."</td>" .
		"</tr>\n");
	echo("<tr>" .
			"<td class=\"tabh01\" width=\"1%\">&nbsp;</td>" .
			"<td class=\"tabh01\" width=\"4%\">"._t('Prefix')."</td>" .
			"<td class=\"tabh01\" width=\"45%\">"._t('Description')."</td>" .
			"<td class=\"tabh01\" width=\"50%\">"._t('Note')."</td>" .
		"</tr>\n");
	while($row = $objSDAO->fetch()){
		if($objSDAO->error == ""){
			$numElem ++;
			echo("<tr>" .
					"<td class=\"text01\" valign='top'><a class=\"text01\" ".
						goToPag("../enty/entityList.php?da=".$row["data_area"]."&xsn=".XSN).
						" title=\""._t("List of Entities")."'".sxHE($row["description"])."'\">".
						"<img src='".SERVER_URL_ROOT."/app/_img/b_browse.png' border='0'>".
						"</a></td>\n" .
					"<td class=\"text01\" valign='top'><a class=\"text01\" ".
						goToPag("../area/dataAreaView.php?da=".$row["data_area"]."&xsn=".XSN).
						" title=\""._t("Data-Area view")."'".sxHE($row["description"])."'\">".
						$row["data_area"]."</a></td>\n" .
					"<td class=\"text01\" valign='top'>".sxHE($row["description"])."</td>" .
					"<td class=\"text01\"><pre class=\"text01\">".sxWW($row["note"])."</pre></td>" .
				"</tr>\n");
		}else{
			echo("<tr>" .
					"<td class=\"text01\" colspan=\"5\">".$objSDAO->error."</td>" .
				"</tr>\n");
		}
	}
	if($numElem == 0)
		echo("<tr>" .
				"<td class=\"text01\" colspan=\"4\">"._t("No Data-Area.")."</td>".
			"</tr>\n");
	echo("</table>\n");
}else{
	echo("<div id=\"mess01\" class=\"mess01\">$errMsg</div>");
}
echo(commandsHTML($aCmd));
echo(footerHTML());
exit();